import os
from fastapi import APIRouter, HTTPException
from api.application.utils.logs import getLogger

app = APIRouter()


@app.get('/api')
async def api() -> dict:
    """测试接口"""
    return {'title': 'fastchat test api'}


@app.get('/exception')
async def exception(name: str) -> dict:
    """测试异常接口"""
    try:
        print(username)
    except Exception as e:
        logger = getLogger(os.environ.get('APP_NAME'))
        logger.error(f"发生错误：{e}")
        raise HTTPException(detail=f"{e}", status_code=500)
    return {}
